package cn.zyl.inwatchappphoneside;

import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.tencent.tws.api.FileTransferManager;
import com.tencent.tws.api.PassThroughDataResultInfo;
import com.tencent.tws.api.PassThroughManager;

public class MainActivity extends AppCompatActivity {

    private Button button;
    private Button button2;
    private TextView mResutlTxt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button = (Button)findViewById(R.id.button);
        button2 = (Button)findViewById(R.id.button2);
        mResutlTxt = (TextView) findViewById(R.id.textView);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String sdcard = Environment.getExternalStorageDirectory().getAbsolutePath();
                FileTransferManager.getInstance(MainActivity.this).sendFile(sdcard+"/zylWatchFace/config.ini", "/zylWatchFace", new FileTransferManager.FileTransferListener() {
                    @Override
                    public void onTransferError(long requestId, String fileName, int errorCode) {
                        mResutlTxt.setText(mResutlTxt.getText().toString() + "onTransferError:" + requestId + "," + fileName + "," + errorCode + "\n");
                    }

                    @Override
                    public void onTransferComplete(long requestId, String filePath) {
                        mResutlTxt.setText(mResutlTxt.getText().toString() + "onTransferComplete:" + requestId + "," + filePath + "\n");
                    }

                    @Override
                    public void onTransferCancel(long requestId, int reason) {
                        mResutlTxt.setText(mResutlTxt.getText().toString() + "onTransferCancel:" + requestId + "," + reason + "\n");
                    }

                    @Override
                    public void onTransferProgress(long requestId, String fileName, long progress) {
                        mResutlTxt.setText(mResutlTxt.getText().toString() + "onTransferProgress:" + requestId + "," + fileName + "," + progress + "\n");
                    }
                });
            }
        });

        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PassThroughManager.getInstance(MainActivity.this).sendData("zyltest", "com.example.zyl.inwatchapp", new PassThroughManager.PassThroughSendDataResultListener() {
                    @Override
                    public void onReceiveSendDataResult(int i) {
//                        PassThroughDataResultInfo.SUC
                        mResutlTxt.setText("SendDateResult:"+i);
                    }
                });
            }
        });
    }
}
